

var Serial = function(){
    var serialport = require("serialport");
    var SerialPort = serialport.SerialPort;

    return {
        getList : function( next){
            var serialArr = [];
            serialport.list(function (err, ports) {
                var found = ports.some(function (p, index, array) {
                    serialArr.push(p.comName);
                });
                next(serialArr);
            });

        },
        open : function(spName ,disConnCallback,openCallback){
            var sp = new SerialPort(spName, {
                baudrate: 115200,
                parser: serialport.parsers.readline("\n"),
                disconnectedCallback:disConnCallback
            },false);
            sp.open( function (err) {
                if (err) {
                    openCallback();
                    return;
                }

                openCallback(sp);
            });

        }
    }

}();
